package com.m1.tzolkin.model.util;

import com.m1.tzolkin.model.exceptions.EndOfGameException;

public class TurnsCounter implements ITurnsCounter {
	
	// ATTRIBUTS
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3982123274637720485L;
	private final int turns;
	private int turn;
	
	// CONSTRUCTEUR
	
	public TurnsCounter(int n) {
		if (n <= 0) {
			throw new IllegalArgumentException();
		}
		turns = n;
	}
	
	// ATTRIBUTS

	@Override
	public int getTurn() {
		return turn;
	}

	@Override
	public int getTurns() {
		return turns;
	}
	
	// COMMANDES

	@Override
	public void incTurn() throws EndOfGameException {
		incTurn(1);
	}

	@Override
	public void incTurn(int d) throws EndOfGameException {
		if (turn + d >= turns) {
			throw new EndOfGameException();
		}
		turn += d;
	}

}
